let sest;
let article;
let hotTitle;

$(function() {
	sest = sessionStorage;
	article = $("#article");
	hotTitle = $("#hot-title");
	articles();
	hotTitles();
	exec1();
});

let exec1 = function() {
	$("body").on("click", "[data-newsId]", function() {
		sest.setItem("articleNewsId", $(this).data("newsid"));
	});
};

let articles = function () {
	$.ajax({
		type: "get",
		url: "a2",
		async: true,
		data: {rowMax : 4},
		success: function(data) {
			console.info("++++++");
			console.info(data);
			console.info("++++++");
			$.each(data, function(i, n) {
				let lis = list01.clone().appendTo(article);
				$.each(n, function(j, k) {
					var newsContent = n.newsContent;
					var index=newsContent.lastIndexOf("src")
					var a = newsContent.substr(index + 5);
					a = a.substr(0, a.indexOf("\""));
					if(index==-1){
				    	lis.find(".newsImg").attr("src","img/_noimg.png");
				    }
				    else if(a!=null && a != "" && a != undefined){
				    	lis.find(".newsImg").attr("src",a);
				    	flag=true;
					}else{
				    	lis.find(".newsImg").attr("src", "img/_noimg.png");
					}
					lis.find("._"+j).text(k);
				});
				lis.find("[data-newsId]").attr("data-newsId", n.newsId);
				lis.find("[data-newsClassId]").attr("data-newsClassId", n.newsClassId);
			});
		}
	});
}

let hotTitles = function() {
	$.ajax({
		type: "get",
		url: "a2",
		async: true,
		data: {},
		success: function(data) {
			//console.info(data);
			hotTitle.empty();
			$.each(data, function(i, n) {
				let li = lis.clone().attr("data-newsId", n.newsId).attr("data-newsClassId", n.newsClassId).appendTo(hotTitle);
				li.find("a").text(n.newsTitle);
			});
		}
	});
}

let list01 = $(`<div class="pui_list_img_txt" style="width:860px; height:209px;">
		<div class="item clearfix" data-newsId data-newsClassId>
			<div class="lbox">
				<a href="article.html" target="_blank" style="width: 238px; height: 160px; background: rgba(0, 0, 0, 0);">
					<div class="fade-box"></div> <img class="newsImg" src="img/sony.jpg" style="opacity: 1; display: block; margin-left: 0px; height: 100%; width: 100%; margin-top: auto;" width="" height=""></a>
			</div>
			<div class="rbox" style="width: 544px;">
				<a href="article.html" target="_blank">
					<h3 class="_newsTitle"></h3></a>
				<div class="des"><span class="_newsWorker"></span></div>
				<ul class="list clearfix">
					<li><i class="iconfont icon-view _newsTime"></i></li>
				</ul>
			</div>
		</div>
	</div>`);

	let lis = $(`
		<li>
			<a href="article.html" target="_blank" class="_newsTitle"></a>
		</li>
	`);